import { IDisposable } from "../../Object/DisposeObject";
import { MessageSerializeHelper } from "./MessageSerializeHelper";

export enum ServiceType {
    Outer,
}

export abstract class AService implements IDisposable {

    private _Id: number;
    public get Id(): number {
        return this._Id;
    }
    public set Id(value: number) {
        this._Id = value;
    }

    private _ServiceType: ServiceType;
    public get ServiceType(): ServiceType {
        return this._ServiceType;
    }

    protected set ServiceType(value: ServiceType) {
        this._ServiceType = value;
    }

    // 缓存上一个发送的消息，这样广播消息的时候省掉多次序列化,这样有个另外的问题,客户端就不能保存发送的消息来减少gc，
    // 不过这个问题并不大，因为客户端发送的消息是比较少的，如果实在需要，也可以修改这个方法，把outer的消息过滤掉。
    protected GetMemoryStream(message: Object) {
        let { stream } = MessageSerializeHelper.MessageToStream(message);
        return stream;
    }

    public Dispose() {
    }

    public abstract Update();

    public abstract Remove(id: number, error: number);

    public abstract IsDispose();

    public abstract Create(id: number, address: string);

    public abstract Send(channelId: number, actorId: number, message);

}